﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;

namespace ERPStore.NewsLetters.Repositories.Mapping
{
	public class CampaignMap : EntityTypeConfiguration<Datas.CampaignData>
	{
		public CampaignMap()
		{
			this.HasKey(e => e.Id);
			this.Property(e => e.Id)
				.IsRequired()
				.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);

			this.Property(t => t.Version)
				.IsRequired()
				.IsFixedLength()
				.IsConcurrencyToken()
				.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)
				.HasMaxLength(8);

			this.HasRequired(p => p.SMTPServer)
				.WithMany(l => l.CampaignList)
				.HasForeignKey(k => k.SMTPServerId);

			this.HasRequired(p => p.NewsLetter)
				.WithMany(l => l.CampaignList)
				.HasForeignKey(k => k.NewsLetterId);

			this.HasRequired(p => p.EmailListSource)
				.WithMany(l => l.CampaignList)
				.HasForeignKey(k => k.EmailListSourceId);

			this.ToTable("NewsLetterCampaign");
		}
	}
}
